﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MeetSomeNearbyStrangerWebApi.ConfigurationSettings
{
    public static class ControllerManager
    {
        private static Dictionary<string, List<ControllerAction>> controllers;

        static ControllerManager()
        {
            controllers = new Dictionary<string, List<ControllerAction>>();
        }

        public static void RegisterController(string controllerName)
        {
            controllers.Add(controllerName, new List<ControllerAction>());
        }

        public static void RegisterAction(string controllerName, ControllerAction action)
        {
            controllers[controllerName].Add(action);
        }

        public static ControllerAction FindActionPerController(string controllerName, string actionName)
        {
            if (!controllers[controllerName].Contains(new ControllerAction() { Name = actionName }))
            {
                throw new ArgumentException(string.Format("No action {0} found for controller {1}.", actionName, controllerName));
            }
            return controllers[controllerName].Find(x => x.Name == actionName);
        }
    }
}